package myPackage.participant.dao;

import myPackage.participant.domain.Parent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;

@Repository
public class ParentDao {
    @Autowired
    private HibernateTemplate hibernateTemplate;

    public List<Parent> listAllParents() {
        return hibernateTemplate.loadAll(Parent.class);
    }

    public Parent getParentByUsername(String username){
        List resultList =  hibernateTemplate.find("from Parent where username=?",username);
        return  resultList.size() == 0?null:(Parent)resultList.get(0);
    }

    public void insert(Parent newParent)
    {
        hibernateTemplate.save(newParent);
    }

    public void update(Parent informationUploaded) {
        hibernateTemplate.update(informationUploaded);
    }
}
